using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string loggedID = UserUtils.GetLoggedID();
        if (loggedID != "") Response.Redirect("loginRs.aspx");
    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        bool cookieSupported = Request.Browser.Cookies;
        lblCookieErr.Visible = !cookieSupported;
        if (!cookieSupported) return;

        string userID = txtUID.Text;
        string encryptedPWD = new Encryptor().MD5Encrypt(txtPWD.Text);
        bool rs = new UserAccBus().UserLogin(userID, encryptedPWD);
        if (rs)
        {
            Response.Cookies["UserLogin"].Value = userID;

            string lastUrl = "loginRs.aspx";
            if (Session["lastUrl"] != null) lastUrl = Session["lastUrl"].ToString();
            Session["lastUrl"] = null;
            Response.Redirect(lastUrl);
        }
        else
        {
            lblErr.Visible = true;
        }
    }
}
